package com.liuceng.peatio.service.job.manual

import com.liuceng.BaseSpec
import com.liuceng.peatio.mapper.MemberAccountLogMapper
import com.liuceng.peatio.model.MemberAccountLog
import com.liuceng.peatio.model.MemberCoefficient
import com.liuceng.peatio.model.NewRptFrontMemberMobileDaily
import com.liuceng.peatio.model.NewRptFrontMemberPcDaily
import com.liuceng.peatio.model.NewRptMemberMediumMobileDailyFlow
import com.liuceng.peatio.model.NewRptMemberMediumPcDailyFlow
import com.liuceng.peatio.service.FrontCampaignService
import com.liuceng.peatio.service.MemberCoefficientService
import com.liuceng.peatio.service.NewRptFrontCampaignDailyService
import sun.util.resources.LocaleData
import java.time.LocalDate

/**
 * Created by liyuhang on 2016-28-4.
 */
class ManualFrontRptDatasJobServiceSpec extends BaseSpec {

    /*def "truth"() {
        expect:
        true
    }*/

    def "测试 单一账号下 mobile端 各渠道的数据 加成系数后的 汇总"() {
        given:
        /**
         * 初始化方法
         */
        MemberCoefficientService memberCoefficientService = new MemberCoefficientService();

        //初始化获取经过系数加成后的数据

        //初始化日预算的数据
        FrontCampaignService frontCampaignService = Stub();
        frontCampaignService.getDayBudget(_ as Integer, _ as Integer) >> {
            memberId, type ->
                if (memberId == 1) {
                    return null
                }
                if (memberId == 2) {
                    return new BigDecimal(800)
                }
                if (memberId == 3) {
                    return new BigDecimal(1600)
                }
                if (memberId == 4) {
                    return new BigDecimal(1800)
                }

                return null
        }
        //初始化已经花费的
        NewRptFrontCampaignDailyService frontCampaignDailyService = Stub();
        frontCampaignDailyService.getAleadyCost(_ as Integer, _ as Integer, _ as LocaleData) >> {
            memberId, type, rptDate ->

                System.out.println(memberId + "--" + type + "--" + rptDate)
                if (memberId == 1 && type == 1) {
                    return new BigDecimal(0)
                }
                if (memberId == 1 && type == 1) {
                    return new BigDecimal(400)
                }
                if (memberId == 2 && type == 2) {
                    return new BigDecimal(400)
                }
                return new BigDecimal(400);
        }

        MemberAccountLogMapper memberAccountLogMapper=Stub();
        memberAccountLogMapper.insertSelective(_ as MemberAccountLog)>>{
            memberAccountLog ->
                return 1
        }

        /**
         * 初始化数据
         */
        and:

        //系数
        MemberCoefficient m1 = new MemberCoefficient(memberId: 1, mediumId: 1, rangeMark: "50,100,150", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 ")
        MemberCoefficient m2 = new MemberCoefficient(memberId: 1, mediumId: 2, rangeMark: "3", values: "6,3,3,4.5")
        // MemberCoefficient m3 = new MemberCoefficient(memberId: 1, mediumId: 3, rangeMark: "5,6,7,8,9,10,12,15,18,20,25,30,35,40,50", values: "1,10,10,8.2,8.2,7.5,7.5,6.5,6.5,6.2,6.2,5.5,5.5,4.5,4.5,3.9,3.9,3.3,3.3,3,3,2.5,2.5,2,2,1.7,1.7,1.7,1.7,1.4,1.4,1.1")
        Map<Integer, MemberCoefficient> mobileMediumCoefficientMap1 = [1: m1, 2: m2]

        //
        LocalDate date = new LocalDate(2016, 5, 9)

        ManualFrontRptDatasJobService service = new ManualFrontRptDatasJobService(memberCoefficientService: memberCoefficientService,
                frontCampaignService: frontCampaignService, frontCampaignDailyService: frontCampaignDailyService,memberAccountLogMapper:memberAccountLogMapper)

        NewRptMemberMediumMobileDailyFlow flow1 = new NewRptMemberMediumMobileDailyFlow(memberId: 1, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 0, mediumId: 1, createdAt: new Date())
        NewRptMemberMediumMobileDailyFlow flow2 = new NewRptMemberMediumMobileDailyFlow(memberId: 1, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 100, mediumId: 2, createdAt: new Date())
        NewRptMemberMediumMobileDailyFlow flow3 = new NewRptMemberMediumMobileDailyFlow(memberId: 1, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 100, mediumId: 3, createdAt: new Date())

        NewRptMemberMediumMobileDailyFlow flow4 = new NewRptMemberMediumMobileDailyFlow(memberId: 2, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 0, mediumId: 1, createdAt: new Date())
        NewRptMemberMediumMobileDailyFlow flow5 = new NewRptMemberMediumMobileDailyFlow(memberId: 2, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 100, mediumId: 2, createdAt: new Date())
        NewRptMemberMediumMobileDailyFlow flow6 = new NewRptMemberMediumMobileDailyFlow(memberId: 2, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 100, mediumId: 3, createdAt: new Date())

        NewRptMemberMediumMobileDailyFlow flow7 = new NewRptMemberMediumMobileDailyFlow(memberId: 3, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 0, mediumId: 1, createdAt: new Date())
        NewRptMemberMediumMobileDailyFlow flow8 = new NewRptMemberMediumMobileDailyFlow(memberId: 3, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 100, mediumId: 2, createdAt: new Date())
        NewRptMemberMediumMobileDailyFlow flow9 = new NewRptMemberMediumMobileDailyFlow(memberId: 3, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 100, mediumId: 3, createdAt: new Date())

        NewRptMemberMediumMobileDailyFlow flow10 = new NewRptMemberMediumMobileDailyFlow(memberId: 4, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 0, mediumId: 1, createdAt: new Date())
        NewRptMemberMediumMobileDailyFlow flow11 = new NewRptMemberMediumMobileDailyFlow(memberId: 4, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 100, mediumId: 2, createdAt: new Date())
        NewRptMemberMediumMobileDailyFlow flow12 = new NewRptMemberMediumMobileDailyFlow(memberId: 4, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 100, mediumId: 3, createdAt: new Date())

        List<NewRptMemberMediumMobileDailyFlow> originMobileMediumDatas1 = [flow1, flow2, flow3]
        List<NewRptMemberMediumMobileDailyFlow> originMobileMediumDatas2 = [flow4, flow5, flow6]
        List<NewRptMemberMediumMobileDailyFlow> originMobileMediumDatas3 = [flow7, flow8, flow9]
        List<NewRptMemberMediumMobileDailyFlow> originMobileMediumDatas4 = [flow10, flow11, flow12]

        when:
        NewRptFrontMemberMobileDaily result = service.convertToFrontMobileMediumDatas(originMobileMediumDatas1, mobileMediumCoefficientMap1, 1, date, 2)

        then: "没有预算 原花费：originalCost==900 经过系数加成的花费：cost==1800"
        result.getCost().compareTo(new BigDecimal(1800)) == 0
        and:
        result.getOriginalCost().compareTo(new BigDecimal(900)) == 0
        result.getMemberId() == 1

        when:
        NewRptFrontMemberMobileDaily result2 = service.convertToFrontMobileMediumDatas(originMobileMediumDatas2, mobileMediumCoefficientMap1, 2, date, 2)

        then: "原花费大于日预算  原花费：originalCost==900 经过系数加成的花费：cost==900"
        result2.getCost().compareTo(new BigDecimal(900)) == 0
        and:
        result2.getOriginalCost().compareTo(new BigDecimal(900)) == 0
        result2.getMemberId() == 2

        when:
        NewRptFrontMemberMobileDaily result3 = service.convertToFrontMobileMediumDatas(originMobileMediumDatas3, mobileMediumCoefficientMap1, 3, date, 2)

        then: "原花费小于日预算 经过系数加成后的数据大于日预算 原花费：originalCost==900 经过系数加成的花费：cost==1600"
        result3.getCost().compareTo(new BigDecimal(1600)) == 0
        and:
        result3.getOriginalCost().compareTo(new BigDecimal(900)) == 0
        result3.getMemberId() == 3


        when:
        NewRptFrontMemberMobileDaily result4 = service.convertToFrontMobileMediumDatas(originMobileMediumDatas4, mobileMediumCoefficientMap1, 4, date, 2)

        then: "经过系数加成后的数据小于等于日预算 原花费：originalCost==900 经过系数加成的花费：cost==1800"
        result4.getCost().compareTo(new BigDecimal(1800)) == 0
        and:
        result4.getOriginalCost().compareTo(new BigDecimal(900)) == 0
        result4.getMemberId() == 4
    }

    def "测试 单一账号下 pc端 各渠道的数据 加成系数后的 汇总"() {
        given:
        /**
         * 初始化方法
         */
        MemberCoefficientService memberCoefficientService = new MemberCoefficientService();

        //初始化获取经过系数加成后的数据

        //初始化日预算的数据
        FrontCampaignService frontCampaignService = Stub();
        frontCampaignService.getDayBudget(_ as Integer, _ as Integer) >> {
            memberId, type ->
                if (memberId == 1) {
                    return null
                }
                if (memberId == 2) {
                    return new BigDecimal(800)
                }
                if (memberId == 3) {
                    return new BigDecimal(1600)
                }
                if (memberId == 4) {
                    return new BigDecimal(1800)
                }

                return 1
        }
        //初始化已经花费的
        NewRptFrontCampaignDailyService frontCampaignDailyService = Stub();
        frontCampaignDailyService.getAleadyCost(_ as Integer, _ as Integer, _ as LocaleData) >> {
            memberId, type, rptDate ->

                System.out.println(memberId + "--" + type + "--" + rptDate)
                if (memberId == 1 && type == 1) {
                    return new BigDecimal(0)
                }
                if (memberId == 1 && type == 1) {
                    return new BigDecimal(400)
                }
                if (memberId == 2 && type == 2) {
                    return new BigDecimal(400)
                }
                return new BigDecimal(400);
        }

        MemberAccountLogMapper memberAccountLogMapper=Stub();
        memberAccountLogMapper.insertSelective(_ as MemberAccountLog)>>{
            memberAccountLog ->
                return 1
        }
        /**
         * 初始化数据
         */
        and:

        //系数
        MemberCoefficient m1 = new MemberCoefficient(memberId: 1, mediumId: 1, rangeMark: "50,100,150", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 ")
        MemberCoefficient m2 = new MemberCoefficient(memberId: 1, mediumId: 2, rangeMark: "3", values: "6,3,3,4.5")
        // MemberCoefficient m3 = new MemberCoefficient(memberId: 1, mediumId: 3, rangeMark: "5,6,7,8,9,10,12,15,18,20,25,30,35,40,50", values: "1,10,10,8.2,8.2,7.5,7.5,6.5,6.5,6.2,6.2,5.5,5.5,4.5,4.5,3.9,3.9,3.3,3.3,3,3,2.5,2.5,2,2,1.7,1.7,1.7,1.7,1.4,1.4,1.1")
        Map<Integer, MemberCoefficient> mobileMediumCoefficientMap1 = [1: m1, 2: m2]

        //
        LocalDate date = new LocalDate(2016, 5, 9)

        ManualFrontRptDatasJobService service = new ManualFrontRptDatasJobService(memberCoefficientService: memberCoefficientService,
                frontCampaignService: frontCampaignService, frontCampaignDailyService: frontCampaignDailyService,memberAccountLogMapper:memberAccountLogMapper)

        NewRptMemberMediumPcDailyFlow flow1 = new NewRptMemberMediumPcDailyFlow(memberId: 1, viewNum: 200, clickNum: 150, cost: 300, validNum: 0, mediumId: 1, createdAt: new Date())
        NewRptMemberMediumPcDailyFlow flow2 = new NewRptMemberMediumPcDailyFlow(memberId: 1, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 2, createdAt: new Date())
        NewRptMemberMediumPcDailyFlow flow3 = new NewRptMemberMediumPcDailyFlow(memberId: 1, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 3, createdAt: new Date())

        NewRptMemberMediumPcDailyFlow flow4 = new NewRptMemberMediumPcDailyFlow(memberId: 2, viewNum: 200, clickNum: 150, cost: 300, validNum: 0, mediumId: 1, createdAt: new Date())
        NewRptMemberMediumPcDailyFlow flow5 = new NewRptMemberMediumPcDailyFlow(memberId: 2, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 2, createdAt: new Date())
        NewRptMemberMediumPcDailyFlow flow6 = new NewRptMemberMediumPcDailyFlow(memberId: 2, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 3, createdAt: new Date())

        NewRptMemberMediumPcDailyFlow flow7 = new NewRptMemberMediumPcDailyFlow(memberId: 3, viewNum: 200, clickNum: 150, cost: 300, validNum: 0, mediumId: 1, createdAt: new Date())
        NewRptMemberMediumPcDailyFlow flow8 = new NewRptMemberMediumPcDailyFlow(memberId: 3, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 2, createdAt: new Date())
        NewRptMemberMediumPcDailyFlow flow9 = new NewRptMemberMediumPcDailyFlow(memberId: 3, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 3, createdAt: new Date())

        NewRptMemberMediumPcDailyFlow flow10 = new NewRptMemberMediumPcDailyFlow(memberId: 4, viewNum: 200, clickNum: 150, cost: 300, validNum: 0, mediumId: 1, createdAt: new Date())
        NewRptMemberMediumPcDailyFlow flow11 = new NewRptMemberMediumPcDailyFlow(memberId: 4, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 2, createdAt: new Date())
        NewRptMemberMediumPcDailyFlow flow12 = new NewRptMemberMediumPcDailyFlow(memberId: 4, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 3, createdAt: new Date())

        List<NewRptMemberMediumPcDailyFlow> originPcMediumDatas1 = [flow1, flow2, flow3]
        List<NewRptMemberMediumPcDailyFlow> originPcMediumDatas2 = [flow4, flow5, flow6]
        List<NewRptMemberMediumPcDailyFlow> originPcMediumDatas3 = [flow7, flow8, flow9]
        List<NewRptMemberMediumPcDailyFlow> originPcMediumDatas4 = [flow10, flow11, flow12]

        when:
        NewRptFrontMemberPcDaily result = service.convertToFrontPcMediumDatas(originPcMediumDatas1, mobileMediumCoefficientMap1, 1, date, 2)

        then: "没有预算 原花费：originalCost==900 经过系数加成的花费：cost==1800"
        result.getCost().compareTo(new BigDecimal(1800)) == 0
        and:
        result.getOriginalCost().compareTo(new BigDecimal(900)) == 0
        result.getMemberId() == 1

        when:
        NewRptFrontMemberPcDaily result2 = service.convertToFrontPcMediumDatas(originPcMediumDatas2, mobileMediumCoefficientMap1, 2, date, 2)

        then: "原花费大于日预算  原花费：originalCost==900 经过系数加成的花费：cost==900"
        result2.getCost().compareTo(new BigDecimal(900)) == 0
        and:
        result2.getOriginalCost().compareTo(new BigDecimal(900)) == 0
        result2.getMemberId() == 2

        when:
        NewRptFrontMemberPcDaily result3 = service.convertToFrontPcMediumDatas(originPcMediumDatas3, mobileMediumCoefficientMap1, 3, date, 2)

        then: "原花费小于日预算 经过系数加成后的数据大于日预算 原花费：originalCost==900 经过系数加成的花费：cost==1600"
        result3.getCost().compareTo(new BigDecimal(1600)) == 0
        and:
        result3.getOriginalCost().compareTo(new BigDecimal(900)) == 0
        result3.getMemberId() == 3


        when:
        NewRptFrontMemberPcDaily result4 = service.convertToFrontPcMediumDatas(originPcMediumDatas4, mobileMediumCoefficientMap1, 4, date, 2)

        then: "经过系数加成后的数据小于等于日预算 原花费：originalCost==900 经过系数加成的花费：cost==1800"
        result4.getCost().compareTo(new BigDecimal(1800)) == 0
        and:
        result4.getOriginalCost().compareTo(new BigDecimal(900)) == 0
        result4.getMemberId() == 4
    }

    def " 测试 所有 需要处理的用户账号的 mob端 各个渠道经过系数加成后 汇总的数据"() {
        given:
        //mobile 移动端系数加成后的数据

        MemberCoefficientService memberCoefficientService = new MemberCoefficientService();

        //初始化获取经过系数加成后的数据

        //初始化日预算的数据
        FrontCampaignService frontCampaignService = Stub();
        frontCampaignService.getDayBudget(_ as Integer, _ as Integer) >> {
            memberId, type ->
                if (memberId == 1) {
                    return null
                }
                if (memberId == 2) {
                    return new BigDecimal(2000)
                }
                if (memberId == 3) {
                    return new BigDecimal(1600)
                }
                if (memberId == 4) {
                    return new BigDecimal(1800)
                }

                return null
        }
        //初始化已经花费的
        NewRptFrontCampaignDailyService frontCampaignDailyService = Stub();
        frontCampaignDailyService.getAleadyCost(_ as Integer, _ as Integer, _ as LocaleData) >> {
            memberId, type, rptDate ->
                System.out.println(memberId + "--" + type + "--" + rptDate)
                if (memberId == 1 && type == 1) {
                    return new BigDecimal(0)
                }
                if (memberId == 1 && type == 1) {
                    return new BigDecimal(400)
                }
                if (memberId == 2 && type == 2) {
                    return new BigDecimal(400)
                }
                return new BigDecimal(400);
        }

        MemberAccountLogMapper memberAccountLogMapper=Stub();
        memberAccountLogMapper.insertSelective(_ as MemberAccountLog)>>{
            memberAccountLog ->
                return 1
        }

        ManualFrontRptDatasJobService service = new ManualFrontRptDatasJobService(memberCoefficientService: memberCoefficientService,
                frontCampaignService: frontCampaignService, frontCampaignDailyService: frontCampaignDailyService,memberAccountLogMapper: memberAccountLogMapper)

        and:
        //初始化数据
        List<Map<String, Integer>> memberIds = [["member_id": 1], ["member_id": 2], ["member_id": 3], ["member_id": 4]]
        Map<Integer, List<NewRptMemberMediumMobileDailyFlow>> originMobileDatasMap =
                [1: [new NewRptMemberMediumMobileDailyFlow(memberId: 1, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 0, mediumId: 1, createdAt: new Date()),
                     new NewRptMemberMediumMobileDailyFlow(memberId: 1, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 100, mediumId: 2, createdAt: new Date()),
                     new NewRptMemberMediumMobileDailyFlow(memberId: 1, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 100, mediumId: 3, createdAt: new Date())],
                 2: [new NewRptMemberMediumMobileDailyFlow(memberId: 2, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 0, mediumId: 1, createdAt: new Date()),
                     new NewRptMemberMediumMobileDailyFlow(memberId: 2, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 100, mediumId: 2, createdAt: new Date()),
                     new NewRptMemberMediumMobileDailyFlow(memberId: 2, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 100, mediumId: 4, createdAt: new Date())],
                 3: [new NewRptMemberMediumMobileDailyFlow(memberId: 3, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 0, mediumId: 1, createdAt: new Date()),
                     new NewRptMemberMediumMobileDailyFlow(memberId: 3, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 0, mediumId: 2, createdAt: new Date()),
                     new NewRptMemberMediumMobileDailyFlow(memberId: 3, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, getphoneNum: 0, mediumId: 3, createdAt: new Date())]
                ]
        Map<Integer, Map<Integer, MemberCoefficient>> mobileCoefficientMap =
                [1: [1: new MemberCoefficient(memberId: 1, mediumId: 1, rangeMark: "3", values: "2,3,3,2.5"),
                     2: new MemberCoefficient(memberId: 1, mediumId: 2, rangeMark: "3,5,10", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 ")],
                 2: [1: new MemberCoefficient(memberId: 2, mediumId: 1, rangeMark: "3", values: "2,3,3,2.5,"),
                     2: new MemberCoefficient(memberId: 2, mediumId: 2, rangeMark: "3,5,10", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 ")],
                 3: [1: new MemberCoefficient(memberId: 3, mediumId: 1, rangeMark: "3", values: "2,3,3,2.5"),
                     2: new MemberCoefficient(memberId: 3, mediumId: 2, rangeMark: "3,5,10", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 "),
                     3: new MemberCoefficient(memberId: 3, mediumId: 3, rangeMark: "50,100,150", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 ")],
                 4: [1: new MemberCoefficient(memberId: 4, mediumId: 1, rangeMark: "3", values: "2,3,3,2.5"),
                     2: new MemberCoefficient(memberId: 4, mediumId: 2, rangeMark: "3,5,10", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 "),
                     3: new MemberCoefficient(memberId: 4, mediumId: 3, rangeMark: "50,100,150", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 ")]]
        LocalDate rptDate = new LocalDate(2016, 5, 9)

        when:

        List<NewRptFrontMemberMobileDaily> result = service.convertToFrontMobileDatas(memberIds, originMobileDatasMap, mobileCoefficientMap, rptDate)
        then: "测试 返回的 的数组长度"
        result.size() == 3

        and: "测试 当没有日预算时"
        result.get(0).getCost().compareTo(new BigDecimal(1800)) == 0

        and: "测试 有日预算时 且已经扣费过"
        result.get(1).getCost().compareTo(new BigDecimal(1800)) == 0

    }

    def " 测试 所有 需要处理的用户账号的 pc端 各个渠道经过系数加成后 汇总的数据"() {
        given:
        //mobile 移动端系数加成后的数据

        MemberCoefficientService memberCoefficientService = new MemberCoefficientService();

        //初始化获取经过系数加成后的数据

        //初始化日预算的数据
        FrontCampaignService frontCampaignService = Stub();
        frontCampaignService.getDayBudget(_ as Integer, _ as Integer) >> {
            memberId, type ->
                if (memberId == 1) {
                    return null
                }
                if (memberId == 2) {
                    return new BigDecimal(2000)
                }
                if (memberId == 3) {
                    return new BigDecimal(1600)
                }
                if (memberId == 4) {
                    return new BigDecimal(1800)
                }

                return null
        }
        //初始化已经花费的
        NewRptFrontCampaignDailyService frontCampaignDailyService = Stub();
        frontCampaignDailyService.getAleadyCost(_ as Integer, _ as Integer, _ as LocaleData) >> {
            memberId, type, rptDate ->
                System.out.println(memberId + "--" + type + "--" + rptDate)
                if (memberId == 1 && type == 1) {
                    return new BigDecimal(0)
                }
                if (memberId == 1 && type == 1) {
                    return new BigDecimal(400)
                }
                if (memberId == 2 && type == 2) {
                    return new BigDecimal(400)
                }
                return new BigDecimal(400);
        }

        MemberAccountLogMapper memberAccountLogMapper=Stub();
        memberAccountLogMapper.insertSelective(_ as MemberAccountLog)>>{
            memberAccountLog ->
                return 1
        }

        ManualFrontRptDatasJobService service = new ManualFrontRptDatasJobService(memberCoefficientService: memberCoefficientService,
                frontCampaignService: frontCampaignService, frontCampaignDailyService: frontCampaignDailyService,memberAccountLogMapper: memberAccountLogMapper)

        and:
        //初始化数据
        List<Map<String, Integer>> memberIds = [["member_id": 1], ["member_id": 2], ["member_id": 3], ["member_id": 4]]
        Map<Integer, List<NewRptMemberMediumPcDailyFlow>> originPcDatasMap =
                [1: [new NewRptMemberMediumPcDailyFlow(memberId: 1, viewNum: 200, clickNum: 150, cost: 300, validNum: 0, mediumId: 1, createdAt: new Date()),
                     new NewRptMemberMediumPcDailyFlow(memberId: 1, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 2, createdAt: new Date()),
                     new NewRptMemberMediumPcDailyFlow(memberId: 1, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 3, createdAt: new Date())],
                 2: [new NewRptMemberMediumPcDailyFlow(memberId: 2, viewNum: 200, clickNum: 150, cost: 300, validNum: 0, mediumId: 1, createdAt: new Date()),
                     new NewRptMemberMediumPcDailyFlow(memberId: 2, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 2, createdAt: new Date()),
                     new NewRptMemberMediumPcDailyFlow(memberId: 2, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 4, createdAt: new Date())],
                 3: [new NewRptMemberMediumPcDailyFlow(memberId: 3, viewNum: 200, clickNum: 150, cost: 300, validNum: 0, mediumId: 1, createdAt: new Date()),
                     new NewRptMemberMediumPcDailyFlow(memberId: 3, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 2, createdAt: new Date()),
                     new NewRptMemberMediumPcDailyFlow(memberId: 3, viewNum: 200, clickNum: 150, cost: 300, validNum: 100, mediumId: 3, createdAt: new Date())]
                ]
        Map<Integer, Map<Integer, MemberCoefficient>> pcCoefficientMap =
                [1: [1: new MemberCoefficient(memberId: 1, mediumId: 1, rangeMark: "3", values: "2,3,3,2.5"),
                     2: new MemberCoefficient(memberId: 1, mediumId: 2, rangeMark: "3,5,10", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 ")],
                 2: [1: new MemberCoefficient(memberId: 2, mediumId: 1, rangeMark: "3", values: "2,3,3,2.5,"),
                     2: new MemberCoefficient(memberId: 2, mediumId: 2, rangeMark: "3,5,10", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 ")],
                 3: [1: new MemberCoefficient(memberId: 3, mediumId: 1, rangeMark: "3", values: "2,3,3,2.5"),
                     2: new MemberCoefficient(memberId: 3, mediumId: 2, rangeMark: "3,5,10", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 "),
                     3: new MemberCoefficient(memberId: 3, mediumId: 3, rangeMark: "50,100,150", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 ")],
                 4: [1: new MemberCoefficient(memberId: 4, mediumId: 1, rangeMark: "3", values: "2,3,3,2.5"),
                     2: new MemberCoefficient(memberId: 4, mediumId: 2, rangeMark: "3,5,10", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 "),
                     3: new MemberCoefficient(memberId: 4, mediumId: 3, rangeMark: "50,100,150", values: "2,3,3,2.5,2.5,1.3,1.3,1.2 ")]]
        LocalDate rptDate = new LocalDate(2016, 5, 9)

        when:

        List<NewRptFrontMemberPcDaily> result = service.convertToFrontPcDatas(memberIds, originPcDatasMap, pcCoefficientMap, rptDate)
        then: "测试 返回的 的数组长度"
        result.size() == 3

        and: "测试 当没有日预算时"
        result.get(0).getCost().compareTo(new BigDecimal(1800)) == 0

        and: "测试 有日预算时 且已经扣费过"
        result.get(1).getCost().compareTo(new BigDecimal(1800)) == 0

    }

    def "测试 获取没有处理的数据 "(){
        given:


        expect:
        true
    }

}